<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      * {
        margin: 0;
        padding: 0;
      }

      li {
        list-style-type: none;
      }

      a {
        text-decoration: none;
        font-size: 14px;
      }

      .nav {
        margin: 100px;
      }

      .nav > li {
        position: relative;
        float: left;
        width: 80px;
        height: 41px;
        text-align: center;
      }

      .nav li a {
        display: block;
        width: 100%;
        height: 100%;
        line-height: 41px;
        color: #333;
      }

      .nav > li > a:hover {
        background-color: #eee;
      }

      .nav ul {
        display: none;
        position: absolute;
        top: 41px;
        left: 0;
        width: 100%;
        border-left: 1px solid #fecc5b;
        border-right: 1px solid #fecc5b;
      }

      .nav ul li {
        border-bottom: 1px solid #fecc5b;
      }

      .nav ul li a:hover {
        background-color: #fff5da;
      }
    </style>
    <script src="https://lib.baomitu.com/jquery/3.6.0/jquery.js"></script>
  </head>

  <body>
    <ul class="nav">
      <li>
        <a href="#">微博</a>
        <ul>
          <li>
            <a href="">私信</a>
          </li>
          <li>
            <a href="">评论</a>
          </li>
          <li>
            <a href="">@我</a>
          </li>
        </ul>
      </li>
      <li>
        <a href="#">微博</a>
        <ul>
          <li>
            <a href="">私信</a>
          </li>
          <li>
            <a href="">评论</a>
          </li>
          <li>
            <a href="">@我</a>
          </li>
        </ul>
      </li>
      <li>
        <a href="#">微博</a>
        <ul>
          <li>
            <a href="">私信</a>
          </li>
          <li>
            <a href="">评论</a>
          </li>
          <li>
            <a href="">@我</a>
          </li>
        </ul>
      </li>
      <li>
        <a href="#">微博</a>
        <ul>
          <li>
            <a href="">私信</a>
          </li>
          <li>
            <a href="">评论</a>
          </li>
          <li>
            <a href="">@我</a>
          </li>
        </ul>
      </li>
    </ul>
    <script>
      /* oldFn(); */
      /* fn1(); */
      /* fn2(); */
      $(".nav>li").hover(function () {
        $(this).children("ul").stop().slideToggle(200);
      });
      function fn1() {
        $(".nav>li").mouseover(function () {
          // $(this) JQuery中的当前元素
          $(this).children("ul").slideDown(200);
        });
        $(".nav>li").mouseout(function () {
          // $(this).children("ul").slideToggle(200);
          $(this).children("ul").slideUp(200);
        });
      }
      function fn2() {
        $(".nav>li").hover(
          function () {
            $(this).children("ul").slideDown(200);
          },
          function () {
            $(this).children("ul").slideUp(200);
          }
        );
      }
      function oldFn() {
        const nav = document.querySelector(".nav");
        const lis = nav.children;
        for (const key in lis) {
          const li = lis[key];
          li.onmouseover = function () {
            li.children[1].style.display = "block";
          };
          li.onmouseout = () => {
            li.children[1].style.display = "none";
          };
        }
      }
    </script>
  </body>
</html>
